Restructuring array with nested objects based on Id and ParentId. Removing empty based on property

welcome to shbcf.ru